package com.zis.task;

import java.io.IOException;
import java.util.Date;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.zis.common.DateUtils;
import com.zis.common.GlobalConfig;

import etcomm.SDK.HttpService.HttpServiceWrapper;

@Component
public class TimerReloadSysInfo {

	protected transient Logger logger = Logger.getLogger(this.getClass().getName());

	
	@Scheduled(cron = "0 */50 */11 * * ?")
	// 每隔11小时50分钟刷新token信息
	public void reloadSysInfo() {
		logger.info(" >>> 加载系统信息定时任务开始执行，当前时间：" + DateUtils.getDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
		try {
			//读取配置文件
			Resource resource = new ClassPathResource("/servConfig.properties");
			Properties pro = PropertiesLoaderUtils.loadProperties(resource);
			String url = pro.getProperty("etcomm.server");//serverURL  
			String account = pro.getProperty("etcomm.entAccount");//用户名 
			String password = pro.getProperty("etcomm.password");//密码
			//读取token
			HttpServiceWrapper hsw = new HttpServiceWrapper(url);
			GlobalConfig.ETC_TOKEN = hsw.Auth(account,password);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
